package cn.com.zero.manager.auth.controller;

import cn.com.zero.api.auth.vo.LockedUserVO;
import cn.com.zero.db.vo.PageParamsVO;
import cn.com.zero.db.vo.PageVO;
import cn.com.zero.manager.auth.constant.ManagerAuthConstants;
import cn.com.zero.manager.auth.service.impl.ManagerLockedUserService;
import cn.com.zero.web.controller.BaseController;
import cn.com.zero.web.util.PageRequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;

/**
 * @author guoxin
 * @version 1.0.0
 * @Description
 * @date 2023/4/3 14:37
 */
@Api(tags = "被锁定管理员管理接口")
@Validated
@RestController
@RequestMapping("/manager/managerLocked")
public class ManagerLockedUserController extends BaseController {

    private ManagerLockedUserService managerLockedUserService;

    @ApiOperation("查询被锁定的管理员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "searchUserIds", value = "用户编号集合"),
            @ApiImplicitParam(paramType = "query", name = "loginIp", value = "登录ip地址"),
            @ApiImplicitParam(paramType = "query", name = "lockedBeginTime", value = "开始时间;格式:yyyy-MM-dd"),
            @ApiImplicitParam(paramType = "query", name = "lockedEndTime", value = "结束时间;格式:yyyy-MM-dd")
    })
    @GetMapping("/list")
    public PageVO<LockedUserVO> queryList(@RequestParam(value = "searchUserIds", required = false) String[] searchUserIds,
                                          @RequestParam(value = "loginIp", required = false) String loginIp,
                                          @RequestParam(value = "lockedBeginTime", required = false) Date lockedBeginTime,
                                          @RequestParam(value = "lockedEndTime", required = false) Date lockedEndTime){
        PageParamsVO pageParamsVO = PageRequestUtil.getPageParams();
        return managerLockedUserService.getLockedUsers(ManagerAuthConstants.MANAGER_SIDE_NAME,pageParamsVO,
                null == searchUserIds ? null : Arrays.asList(searchUserIds), loginIp, lockedBeginTime, lockedEndTime);
    }

    @ApiOperation(value = "解锁管理员")
    @ApiImplicitParam(paramType = "path", name = "userId", required = true, value = "用户ID")
    @DeleteMapping("/unlock/{userId}")
    public void unlockAdmin(@PathVariable("userId") String userId){
        managerLockedUserService.unlockUser(ManagerAuthConstants.MANAGER_SIDE_NAME,userId);
    }

    @Autowired
    public void setManagerLockedUserService(ManagerLockedUserService managerLockedUserService) {
        this.managerLockedUserService = managerLockedUserService;
    }
}
